package logic

import (
	"B/models/mysql"
	"context"
	"fmt"

	"B/internal/svc"
	"B/shenzhousrv"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserNoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserNoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserNoLogic {
	return &UserNoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserNoLogic) UserNo(in *shenzhousrv.UserNoRequest) (*shenzhousrv.UserNoResponse, error) {
	// todo: add your logic here and delete this line
	var user mysql.User
	err := user.FindUser(in.Phone)
	if err != nil {
		return nil, fmt.Errorf("查询用户失败")
	}
	if user.ID == 0 {
		return nil, fmt.Errorf("该用户不存在")
	}
	user.Status = 0
	err = user.UpdateUser()
	if err != nil {
		return nil, fmt.Errorf("用户冻结失败")
	}
	return &shenzhousrv.UserNoResponse{}, nil
}
